<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<link rel="stylesheet" type="text/css" href="<c:url value='/css/course-index.css'/>" />
<script src="<c:url value='/js/courseNewClass.js'/>" type="text/javascript" charset="utf-8"></script> 

<!--新建班级-->

<div class="row">
	<div class="col-md-2 col-lg-2"></div>
	<div class="col-md-8 col-lg-8">
		<div class="new-class-title">新建班级</div>
		<form>
			<div class="form-group">
				<div class="row">
					<div class="col-md-4 col-lg-4">
						<label for="term">班级类型</label>
					</div>
					<div class="col-md-6 col-lg-6">
						<input type="text" class="form-control" id="addClassType" value="授课大班" readonly>
					</div>
				</div>
			</div>
			<div class="form-group className">
				<div class="row">
					<div class="col-md-4 col-lg-4">
						<label for="className">班级名称</label>
					</div>
					<div class="col-md-6 col-lg-6">
						<input type="text" class="form-control" name="addClassName">
					</div>
				</div>
			</div>
			
			<div class="form-group has_theory">
				<div class="row">
					<div class="col-md-4 col-lg-4">
						<label for="term">是否有理论课</label>
					</div>
					<div class="col-md-6 col-lg-6">
						<select class="form-control" id="addHasTheory" onclick="selectTheory(this)">
							<option value="err" selected>---</option>
							<option value="1">是</option>
							<option value="0">否</option>
						</select>
					</div>
				</div>
			</div>
			
			<div class="form-group theory_sum_week">
				<div class="row">
					<div class="col-md-4 col-lg-4">
						<label for="">理论课总周数</label>
					</div>
					<div class="col-md-6 col-lg-6">
						<input type="text" class="form-control" id="" name="theorySumWeeks" onkeyup='this.value=this.value.replace(/\D/gi,"")'>
					</div>
				</div>
			</div>
			
			<div class="form-group theory_date_str">
				<div class="row">
					<div class="col-md-4 col-lg-4">
						<label for="">理论课程节次/周</label>
					</div>
					<div class="col-md-6 col-lg-6">
						<input type="text" class="form-control" name="addTheoryDate" id="theory_date_str" onkeyup='this.value=this.value.replace(/\D/gi,"")'>
					</div>
				</div>
			</div>
			<div id="theory_date_list"></div>
			<div class="form-group add-theory-time">
				<button type="button" class="btn btn-primary" onclick="addtheoryTime()">添加理论课上课时间及上课地点</button>
			</div>
			
			<div class="form-group has_lab">
				<div class="row">
					<div class="col-md-4 col-lg-4">
						<label for="term">是否有实验课</label>
					</div>
					<div class="col-md-6 col-lg-6">
						<select class="form-control" id="addHasLab" onclick="selectLab(this)">
							<option value="err" selected>---</option>
							<option value="1">是</option>
							<option value="0">否</option>
						</select>
					</div>
				</div>
			</div>
			
			<div class="form-group lab_sum_week">
				<div class="row">
					<div class="col-md-4 col-lg-4">
						<label for="">实验课总周数</label>
					</div>
					<div class="col-md-6 col-lg-6">
						<input type="text" class="form-control" id="" name="labSumWeeks"  onkeyup='this.value=this.value.replace(/\D/gi,"")'>
					</div>
				</div>
			</div>
			<div class="form-group lab_date_str">
				<div class="row">
					<div class="col-md-4 col-lg-4">
						<label for="">实验课程节次/周</label>
					</div>
					<div class="col-md-6 col-lg-6">
						<input type="text" class="form-control" name="addLabDate" id="lab_date_str"  onkeyup='this.value=this.value.replace(/\D/gi,"")'>
					</div>
				</div>
			</div>
			<div id="lab_date_list"></div>
			<div class="form-group add-lab-time">
				<button type="button" class="btn btn-primary" onclick="addlabTime()">添加实验课上课时间及上课地点</button>
			</div>

		</form>
		<div style="text-align:center;">
			<button class="btn btn-primary" id="addClass">确定</button>
		</div>
	</div>
	<div class="col-md-2 col-lg-2"></div>
</div>

<script>
$(function() {
	$("#addClass").click(addClass);
});
var addClass = function(){
	var courseId=data.data.courseId;
	var classType=$("#addClassType").val();
	var name=$("input[name='addClassName']").val();
	var hasTheory=$("#addHasTheory").val();
	var hasLab=$("#addHasLab").val();
	var fid=$("#classList").val();
	var assistantId=$("#assistantList").val();

	var theoryDate={};
	var labDate={};
	 if(hasTheory==1){
		 var tlocation=$("input[name='t-location']").val();
		 var theorySumWeeks=$("input[name='theorySumWeeks']").val();
		 var theoryTimeOfWeek=$("input[name='addTheoryDate']").val();
		 var date=[];
		 for(var i=0;i<theoryTimeOfWeek;i++){
			 var item={
					 begin:parseDate($("#t-time-start"+(i+1)).val()),
			    	 end:parseDate($("#t-time-end"+(i+1)).val()),
			    	 location:$("#t-location"+(i+1)).val()

			 }
			 date.push(item);
			 console.log(item);
		 }
		var theoryDate={
					sumWeeks:theorySumWeeks,
					timeOfWeek:theoryTimeOfWeek,
					date:date
			}
	 }

	 if(hasLab==1){
		 var llocation=$("input[name='l-location']").val();
		 var labSumWeeks=$("input[name='labSumWeeks']").val();
		 var labTimeOfWeek=$("input[name='addLabDate']").val();
		 var date=[];
		 for(var i=0;i<labTimeOfWeek;i++){
			 var item={
					 begin:parseDate($("#l-time-start"+(i+1)).val()),
			    	 end:parseDate($("#l-time-end"+(i+1)).val()),
			    	 location:$("#l-location"+(i+1)).val()
			 }
			 date.push(item);
			 console.log(item);
		 }
		var labDate={
					sumWeeks:labSumWeeks,
					timeOfWeek:labTimeOfWeek,
					date:date
			}
	 }
	 var json={
				name:name,
				courseId:courseId,
				classType:"CLASS",
				hasTheory:hasTheory,
				theoryDate:theoryDate,
				hasLab:hasLab,
				labDate:labDate
		}
	 $.post(CONTEXT_PATH+"class/ajaxCreate", {
			data : JSON.stringify(json)
		}, function(data) {
			if(data.status=="success"){
				window.location.reload();
			}else{
				layer.msg("请输入班级信息！");
			}
		});
}
</script>